home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / AppsToGo / DTS.Draw / TGroupObj.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-22  |  5.1 KB  |  179 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** File:        TGroupObj.c
  5. ** Written by:    Eric Soldan
  6. **
  7. ** Copyright © 1992 Apple Computer, Inc.
  8. ** All rights reserved.
  9. */
  10.  
  11. /* You may incorporate this sample code into your applications without
  12. ** restriction, though the sample code has been provided "AS IS" and the
  13. ** responsibility for its operation is 100% yours.  However, what you are
  14. ** not permitted to do is to redistribute the source as "DSC Sample Code"
  15. ** after having made changes. If you're going to re-distribute the source,
  16. ** we require that you make it clear in the source that the code was
  17. ** descended from Apple Sample Code, but that you've made changes. */
  18.  
  19. /* See the files "=How to write your app" and "=Using TreeObj.c" for information
  20. ** on this function. */
  21.  
  22. /* The group object is used as a parent of objects that are to be grouped.
  23. ** By having a group parent object, the children are understood to be grouped.
  24. ** This allows a hierarchy of groups.
  25. **
  26. ** Group objects can't be clicked on.  Their members can, however.  This means
  27. ** that hit-testing for a group always returns false.  When an actual object is
  28. ** hit, it actually returns itself only if the parent isn't a group.  A hit on
  29. ** an actual object causes the object to look at the parent.  If the parent is
  30. ** a group, then it wants to return the parent as the object hit.  If in turn that
  31. ** parent is a group, it continues up the chain until a non-group object is hit.
  32. ** For this sample application the first non-group parent will always be the root
  33. ** object.
  34. **
  35. ** The above parent check for hit-testing means that the highest order object
  36. ** in the group will always be returned, thus indicating that all members of the
  37. ** group should be considered selected.  That is the exact implementation we use.
  38. **
  39. ** This also means that only objects directly off the root can be selected.  The
  40. ** object will either be the highest order group object, or it will be an actual
  41. ** object directly off the root.
  42. **
  43. ** It seems kind of odd that a group object can be selected, but it can't be hit.
  44. ** This does actually make sense, since if any one of the members of the group is
  45. ** hit, the entire group should be considered a single entity, and the highest
  46. ** order group object would then naturally be the object to select. */
  47.  
  48.  
  49.  
  50. /*****************************************************************************/
  51.  
  52.  
  53.  
  54. #include "App.h"            /* Get the application includes/typedefs, etc.    */
  55. #include "App.protos.h"        /* Get the prototypes for the application.        */
  56.  
  57. #ifndef __OSEVENTS__
  58. #include <OSEvents.h>
  59. #endif
  60.  
  61. #ifndef __OSUTILS__
  62. #include <OSUtils.h>
  63. #endif
  64.  
  65. #ifndef __QUICKDRAW__
  66. #include <Quickdraw.h>
  67. #endif
  68.  
  69. #ifndef __TREEOBJ2__
  70. #include "TreeObj2.h"
  71. #endif
  72.  
  73. #ifndef __UTILITIES__
  74. #include "Utilities.h"
  75. #endif
  76.  
  77.  
  78.  
  79.  
  80. /*****************************************************************************/
  81.  
  82.  
  83.  
  84. static GroupObjPeek    *gMWERKSDebug;
  85.     /* For Metroweks debugging of AppsToGo "objects", you need an instance of the
  86.     ** same type you wish to view it in the debugger.  Now we have an instance. */
  87.  
  88.  
  89.  
  90. /*****************************************************************************/
  91. /*****************************************************************************/
  92.  
  93. #ifdef applec
  94. #pragma segment DTSDrawSeg2
  95. #endif
  96.  
  97. /*****************************************************************************/
  98. /*****************************************************************************/
  99.  
  100.  
  101.  
  102. long    TGroupObj(TreeObjHndl hndl, short message, long data)
  103. {
  104. #if VH_VERSION
  105.     char    *cptr;
  106.     Rect    rct;
  107. #endif
  108.  
  109.     switch (message) {
  110.         case FREEMESSAGE:        /* For these messages, the TRect behavior is what we want. */
  111.         case COPYMESSAGE:
  112.         case UNDOMESSAGE:
  113.         case CONVERTMESSAGE:
  114.         case FREADMESSAGE:
  115.         case FWRITEMESSAGE:
  116.         case HREADMESSAGE:
  117.         case HWRITEMESSAGE:
  118.         case GETOBJRECTMESSAGE:
  119.         case SETOBJRECTMESSAGE:
  120.         case SECTOBJRECTMESSAGE:
  121.         case GETBBOXMESSAGE:
  122.         case CLICKMESSAGE:
  123.         case SETSELECTMESSAGE:
  124.         case GETSELECTMESSAGE:
  125.         case COMPAREMESSAGE:
  126.             return(TRectObj(hndl, message, data));
  127.             break;
  128.  
  129.         case INITMESSAGE:
  130.             break;
  131.  
  132.         case HITTESTMESSAGE:
  133.             return(0L);                /* Groups can not directly be hit. */
  134.             break;
  135.  
  136.         case GETRGNMESSAGE:
  137.             return((long)NewRgn());    /* The region is used for hit-testing, so return an empty rgn. */
  138.             break;
  139.  
  140.         case DRAWMESSAGE:
  141.             if (data == DRAWSELECT)
  142.                 TRectObj(hndl, message, data);
  143.                     /* Draw the selection indicators, bu the group has no body. */
  144.             break;
  145.  
  146. #if VH_VERSION
  147.         case VHMESSAGE:
  148.             cptr = ((VHFormatDataPtr)data)->data;
  149.             ccatchr(cptr, 13, 2);
  150.             ccat   (cptr, "$10: TGroupObj:");
  151.             ccatchr(cptr, 13, 1);
  152.             ccat   (cptr, "  $00: selected = ");
  153.             ccatdec(cptr, mDerefGroup(hndl)->selected);
  154.             ccatchr(cptr, 13, 1);
  155.             
  156.             rct = mDerefGroup(hndl)->group;
  157.             ccat      (cptr, "  $02: group    = ($");
  158.             ccatpadhex(cptr, 0, 4, 4, rct.top);
  159.             ccat      (cptr, ",$");
  160.             ccatpadhex(cptr, 0, 4, 4, rct.left);
  161.             ccat      (cptr, ",$");
  162.             ccatpadhex(cptr, 0, 4, 4, rct.bottom);
  163.             ccat      (cptr, ",$");
  164.             ccatpadhex(cptr, 0, 4, 4, rct.right);
  165.             ccat      (cptr, ")");
  166.             return(true);
  167.             break;
  168. #endif
  169.  
  170.         default:
  171.             break;
  172.     }
  173.  
  174.     return(noErr);
  175. }
  176.  
  177.  
  178.  
  179.